/*
 * @lc app=leetcode.cn id=415 lang=csharp
 *
 * [415] 字符串相加
 */

// @lc code=start
public class Solution {
    public string AddStrings(string num1, string num2) {
        int i = num1.Length - 1, j = num2.Length - 1, add = 0;
        StringBuilder sb = new StringBuilder();
        while(i >= 0 || j >= 0 || add != 0)
        {
            int x = i >= 0 ? num1[i] - '0' : 0;
            int y = j >= 0 ? num2[j] - '0' : 0;
            int result = x + y + add;
            sb.Append(result % 10);
            add = result / 10;
            i--;
            j--;
        }
        char[] chars = sb.ToString().ToCharArray();
        Array.Reverse(chars);
        return new string(chars);
    
    }
}
// @lc code=end

